package com.groupbuying.common.baseutils.baseframework4plugins.basecrud.vo;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntUnaryOperator;


/**
 * @anthor zmlmagic
 * @date 2018/12/25 5:21 PM
 * @company 蒙泰互联网公司
 * @des 备注说明
 **/

public class BaseModel implements Serializable {
    public static final int DEL_FLAG_VALID = 1;
    public static final int DEL_FLAG_INVALID = 2;

    public static final String DEL_FLAGTURE_VALID = "1";
    public static final String DEL_FLAGTURE_INVALID = "2";

    //private int delFlag = 1;
    private String sortName = "opeTime";
    private String sortType = "desc";
    //private int version;

    public BaseModel() {
    }

    public static String genUuid() {
        String str = UUID.randomUUID().toString();
        return str.replaceAll("-", "");
    }

    public static String getNextUuid(String preKey) {
        return preKey + createRandomID();
    }

    public static String createRandomID() {
        DateTimeFormatter datetimeFormatter = DateTimeFormatter.ofPattern("yyyMMddHHmmssSSS");
        LocalDateTime now = LocalDateTime.now();
        String id1 = now.format(datetimeFormatter);
        IntUnaryOperator updateFunction = (int i) -> {
            if (i >= 1_000_000) {
                return 0;
            }
            return i + 1;
        };
        AtomicInteger atomic = new AtomicInteger();
        return String.format("%s%01d", id1, atomic.updateAndGet(updateFunction));
    }

//    public int getDelFlag() {
//        return this.delFlag;
//    }

//    public void setDelFlag(int delFlag) {
//        this.delFlag = delFlag;
//    }

    public String getSortName() {
        return this.sortName;
    }

    public void setSortName(String sortName) {
        this.sortName = sortName;
    }

    public String getSortType() {
        return this.sortType;
    }

    public void setSortType(String sortType) {
        this.sortType = sortType;
    }
}
